package com.csthink.mr.serial.mobile;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @author <a href="mailto:csthink@icloud.com">Mars</a>
 * @since 2024-04-12 20:16
 */
public class AccessReducer extends Reducer<Text, Access, NullWritable, Access> {

    @Override
    protected void reduce(Text phone, Iterable<Access> values, Context context) throws IOException, InterruptedException {
        long upCount = 0;
        long downCount = 0;

        for (Access access : values) {
            upCount += access.getUp();
            downCount += access.getDown();
        }

        context.write(NullWritable.get(), new Access(phone.toString(), upCount, downCount));
    }
}
